$(function(){
	load_record_grid('getPayments.action');
	
	function load_record_grid(url){
        $('#record_grid').datagrid({
	        title : '销售记录',
	        iconCls: 'icon-edit',
	        url:url,
	        method:'post',
	        loadMsg : '正在加载…',
	        fit : true, 
	        nowrap: false, //设置为true，当数据长度超出列宽时将会自动截取
	        fitColumns : true, 
	        singleSelect : true, // 每次只选中一行
	        sortName : 'paymentId', //默认排序字段
	        sortOrder : 'desc',
	        striped : true,  // 隔行变色  
	        pagination : true,  // 分页
	        pageNumber : 1, // 初始化页码 
	        pageSize : 10,  // 指定每页10条记录，服务器要加上page属性和total属性
	        pageList : [ 10, 20, 30, 50 ], // 可以设置每页记录条数的列表，服务器要加上rows属性
	        idField : 'paymentId', // 主键属性
            rownumbers : true, //显示行号  
	        frozenColumns : [ [
		        {title : '支付单流水号', width : '170', field : 'paymentId', sortable : true}, 
		        {title : '交易时间', width : '170',    field : 'createTime',sortable : true, editor:'text'},
		        {title : '会员编号', width:'90',field:'customerId',sortable:false, editor:'text'},
		        {title : '会员姓名', width:'90',field:'customerName',sortable:false, editor:'text'},
		        {title : '折扣', width:'90',field:'discount',sortable:false, editor:'text'},
		        {title : '商品数目', width:'90',field:'amount',sortable:true, editor:'text'},
		        {title : '总金额', width:'90',field:'receivables',sortable:true, editor:'text'},
		        {title : '收银员', width:'90',field:'cashier',sortable:true, editor:'text'},
		        {title : '状态', width:'90',field:'state',sortable:true, editor:'text'},
		        
	        ] ],
	        toolbar : '#tb'
	        
	    });
	}
	
	/*搜索*/
	$('#btn_search_date').bind('click', function(){
		$('#search_date').form('submit',{
			success: function(){
				var beginDate = ($("#firstDate").datebox("getValue"));
				var endDate = ($("#lastDate").datebox("getValue"));
				var customerId = $("#customerId").textbox('getValue');
				var url = 'searchSaleRecord.action?beginDate='+beginDate+'&endDate='+endDate+'&customerId='+customerId;
				load_record_grid(url);
			}
		});
		
    });
	
});